/**
 * ClassName 员工工具控制器（天气详情和快递查询）
 */
Ext.define("app.controller.ToolController",{	
	extend:'Ext.app.Controller',
	init: function(){
		this.control({	
			//天气面板渲染时请求天气数据
			'toolweatherforecast': {
				render: 'getWeather'
			},
			
			//点击查询指定城市的天气
			'toolweatherforecast button[action=submitBtn]': {
				click: 'weatherSubmitBtn'
			},
			
			//点击查询快递
			'toolexpress button[action=submitBtn]': {
				click: 'expressSubmitBtn'
			},
		})
	},
	
	//点击查询天气按钮
	weatherSubmitBtn: function(btn){
		var panel = btn.ownerCt.ownerCt;
		//表单提交前，验证表单有效性
		if(panel.down('form').isValid()){
			smsObj.ToolWeatherforecast(panel, btn.ownerCt.down('textfield[name=cityname]').getValue());
		}else{
			Ext.Msg.alert('警告', '请输入合法值~');
		}
		
	},
	
	//天气面板渲染时请求天气数据，把数据填充到相应的组件上去
	getWeather: function(thiss){		
		smsObj.ToolWeatherforecast(thiss, '');
	},
	
	//点击查询快递
	expressSubmitBtn: function(btn){		
		//表格面板组件
		var panel = btn.ownerCt.ownerCt;
		//表格面板的store
		var store = panel.down('gridpanel').getStore();
		//表单提交前，验证表单有效性
		if(panel.down('form').isValid()){
			var formData = panel.down('form').getValues();
			//提交查询，直接store.load时传入额外参数即可
			store.load({params: {company: formData.company, expressNumber: formData.expressNumber}});
		}else{
			Ext.Msg.alert('警告', '请输入合法值~');
		}
		
	},
		
	views:[
	    'tool.Weatherforecast',//天气视图
	    'tool.Express'//快递视图
	],
	stores:[
	    'ToolExpressCompanyStore',//快递公司的store
	    'ToolExpressDataStore',//快递信息详情的store
	]
});